package com.jacobson.core.mvp

import com.jacobson.core.framework.delegation.WeakRef
import com.jacobson.core.framework.errorhandler.RxErrorHandler
import com.jacobson.core.widget.logger.LoggerFactory
import javax.inject.Inject

/**
 * ================================================
 *
 *  @author Wucz on 2018/7/21 15:04
 * ================================================
 */
open class BasePresenter<V : IView, out M : IModel>(
        view: V,
        val model: M
) : IPresenter {
    protected val logger = LoggerFactory.getLogger(javaClass, "${javaClass.simpleName} >>> ")
    protected var view: V? by WeakRef { view }

    @Inject
    lateinit var rxErrorHandler: RxErrorHandler


    override fun onStart() {
        logger.d("Presenter: onStart -> $view")
    }

    override fun onDestroy() {
        view = null
        logger.d("Presenter: onDestroy -> $view")
    }


    protected fun startLoading(page: Int = 1, type: Int = 0, extra: Any = 0) {
        if (page <= 1) {
            //下拉刷新
            this.view?.startLoading(type, extra)
        }
    }
}